package com.example.mybatis_demo.config;

import com.example.mybatis_demo.datasource.MybatisDatasourceInterceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class MybatisInterceptorsConfig implements SmartInitializingSingleton {

    @Resource
    private SqlSessionFactory sqlSessionFactory;
    @Override
    public void afterSingletonsInstantiated() {
        sqlSessionFactory.getConfiguration().addInterceptor(new MybatisDatasourceInterceptor());
    }
}
